package com.example.themyno1;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    // 声明控件
    private Button loginButton;
    private ImageView iconImageView;

    // 声明输入框控件
    private EditText usernameEditText;
    private EditText passwordEditText;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        // 绑定控件
        loginButton = findViewById(R.id.btn_login);
        iconImageView = findViewById(R.id.img_icon);
        usernameEditText = findViewById(R.id.Edit_name);
        passwordEditText = findViewById(R.id.Edit_password);

        // 设置监听事件
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username = usernameEditText.getText().toString();
                String password = passwordEditText.getText().toString();

                if (!isValidUsername(username)) {
                    Toast.makeText(MainActivity.this, "请输入正确的用户名！！！", Toast.LENGTH_SHORT).show();
                } else if (!isValidPassword(password)) {
                    Toast.makeText(MainActivity.this, "请输入正确的密码！！！", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, "恭喜" + username + "登录成功了！" + "你的密码是：" + password, Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private boolean isValidUsername(String username) {
        return "test".equals(username);
    }

    private boolean isValidPassword(String password) {
        return "123456".equals(password);
    }
}